#include "../include/JsonParser.h"

#include "../libjson/include/CJsonParseFactory.h"
#include "../libjson/include/IJsonParser.h"

#pragma comment(lib,"libjson/lib/jsonParser.lib")

JsonParser::JsonParser(void)
{

}

JsonParser::~JsonParser(void)
{
	
}

//DataSourceStatus JsonParser::ParseDataSourceStatus( char* strJson )
//{
//	DataSourceStatus status(true,"5555555555");
//	return status;
//}

DataSourceStatus JsonParser::ParseDataSourceStatus( char* strJson )
{
	IJsonParser* pParser=CJsonParseFactory::GetInstance()->CreateJsonParser();
	AdCasterAdStatus _status;
	std::string strTemp=strJson;
	pParser->ParserStatus(strTemp,_status);

	bool bRuning=_status.status=="1"?true:false;
	DataSourceStatus status(bRuning,_status.cacheTimeStamp);

	return status;
}

std::vector<Slot> JsonParser::ParseSlots(char* strJson)
{
	std::vector<Slot> slots;
	IJsonParser* pParser=CJsonParseFactory::GetInstance()->CreateJsonParser();

	SLOTS_VECTOR _slots;
	pParser->ParserSlots(strJson,_slots);

	for (unsigned int i=0;i<_slots.size();i++)
	{
		Slot slot;
		slot.m_id=_slots[i].id;
		slot.m_xPos = _slots[i].xPos;
		slot.m_yPos = _slots[i].yPos;
		slot.m_width = _slots[i].width;
		slot.m_height = _slots[i].height; 
		slot.m_version = _slots[i].version;
		slots.push_back(slot);
	}
	return slots;
}